package cn.zt.ztzx.service.impl;

import cn.zt.utils.Result;
import cn.zt.ztzx.domain.dto.DeviceGatherDto;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.zt.ztzx.domain.DeviceGather;
import cn.zt.ztzx.service.DeviceGatherService;
import cn.zt.ztzx.mapper.DeviceGatherMapper;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 不.凌
* @description 针对表【t_device_gather】的数据库操作Service实现
* @createDate 2024-10-11 09:58:41
*/
@Service
public class DeviceGatherServiceImpl extends ServiceImpl<DeviceGatherMapper, DeviceGather>
    implements DeviceGatherService{

    @Override
    public Result deviceGatherListPage(DeviceGatherDto deviceGatherDto) {
        Page<DeviceGather> page= new Page<>(deviceGatherDto.getPageNum(), deviceGatherDto.getPageSize());
        LambdaQueryWrapper<DeviceGather> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(deviceGatherDto.getDeviceName()), DeviceGather::getDeviceName, deviceGatherDto.getDeviceName());
        this.page(page,wrapper);
        return Result.success(page);
    }

    @Override
    public Result deviceGatherSave(DeviceGather deviceGather) {
        deviceGather.setCreateTime(new Date());
        boolean save = this.save(deviceGather);
        return Result.success(save);
    }

    @Override
    public Result deviceGatherUpdate(DeviceGather deviceGather) {
        deviceGather.setUpdateTime(new Date());
        boolean update = this.updateById(deviceGather);
        return Result.success(update);
    }

    @Override
    public Result deviceGatherDelete(Integer id) {
        boolean remove = this.removeById(id);
        return Result.success(remove);
    }
}




